$(function(){

    var currentPage = 1;
    var pageSize = 0;
    var count = 0;
    var page = 0;
    function render(){
        $.ajax({
            url:'http://127.0.0.1:9090/api/getmoneyctrl',
            data:{pageid:currentPage},
            dataType:'json',
            success:function(info){
                // console.log(info);
                $('.list').html(template('tmp',info));

                pageSize = info.pagesize;
                count = info.totalCount;
                page = Math.ceil(count/pageSize);

                var str = '';
                for(var i=1;i<=page;i++){
                    if(i == currentPage){
                        str += '<option value="'+i+'"selected >'+i+'/'+page+'</option>';
                    }else{
                        str += '<option value='+i+'>'+i+'/'+page+'</option>';
                    }
                }

                $('#selectpage').html(str);

            }
        })
    }
    render();

    // 下拉菜单
    $('#selectpage').change(function(){
        var id = $(this).val();
        currentPage = id;
        render();
    })

    // 上一页
    $('.pre').click(function(){
        if(currentPage >1){
            currentPage--;
            render();
        }else{
            mui.toast('已经第一页！');
        }
    })
    // 下一页
    $('.next').click(function(){
        if(currentPage<page){
            currentPage++;
            render();
        }else{
            mui.toast('已经最后一页！');
        }
    })

})